package exception;

/**
 * try{
 *     正常的代码块
 *
 * }catch(xxxException){}
 *
 */
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        // 空指针异常
        String str = "java";
        try {
            System.out.println(str.length());
            System.out.println(str.charAt(5));
            System.out.println(Integer.parseInt(str));
        }catch (NullPointerException|StringIndexOutOfBoundsException e){
            System.out.println("出现了空指针异常或者字符串下表越界异常");
        }catch(Exception e){
            System.out.println("出现了未知异常");
        }
        finally {
            System.out.println("finally");
        }

        System.out.println("程序结束了");
    }
}
